package config

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"os"
)

var (
	//Conf config.json
	Conf *Config
)

//Config config.json
type Config struct {
	Debug  bool
	Listen string
	Auth   struct {
		CallbackURL string
		AppName     string
		AppKey      string
		AuthHost    string
	}
}

func load(file string, data interface{}) error {
	d, err := ioutil.ReadFile(file)
	if err != nil {
		return err
	}
	return json.Unmarshal(d, data)
}

func init() {
	Conf = &Config{}
	err := load("./config.json", Conf)
	if err != nil {
		log.Println(err)
		os.Exit(-1)
	}
	fmt.Printf("Load config:%+v\n", Conf)
}
